package com.kly.user.serviceImpl.ppv;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.common.api.Response;
import com.kly.user.db.dao.UserPpvUnlockRecordDao;
import com.kly.user.db.entity.UserPpvUnlockRecordEntity;
import com.kly.user.dto.ppv.PpvLogDto;
import com.kly.user.service.PPVLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service("ppvLogService")
public class PPVLogServiceImpl implements PPVLogService {

    @Resource
    UserPpvUnlockRecordDao userPpvUnlockRecordDao;

    @Override
    public Response addPPVLog(PpvLogDto dto) {
        final UserPpvUnlockRecordEntity addResult = userPpvUnlockRecordDao.addPPVLog(dto.getRequestId(), dto.getUserCode(), dto.getModelUserCode(), dto.getChatterUserCode(), dto.getBenefitCode(), dto.getMsgId(), dto.getImageCode(), dto.getImageUrl());
        if (addResult == null) {
            log.error("addPPVLogFailed, request:{}", JSONObject.toJSONString(addResult));
            return Response.error("addPPVLogFailed, request:{}");
        }
        return Response.ok();
    }

    @Override
    public Response<Integer> updateResult(String requestId, Integer status, String result, String imageCode, String imageUrl, String chatterUserCode) {
        final Integer updateResult = userPpvUnlockRecordDao.updateResult(requestId, status, result, imageCode, imageUrl, chatterUserCode);
        return Response.ok(updateResult);
    }
}
